<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const user = {
            name:'佐助',
            age:20,
            wife:{
                name : '小樱',
                age:22
            }
        }
        //把目标对象变成代理对象
        //参数1:user ==> target目标对象
        //参数2:handler ==> 处理器对象,用来监视数据,及数据的操作
        const proxyUser = new Proxy(user,{
            get(target, prop) {
                console.log('get方法调用了', target, prop);
                return Reflect.get(target,prop)
            },
            set(target, prop,val) {
                console.log('set方法调用了');
                return Reflect.set(target,prop,val)
            },
            deleteProperty(target,prop) {
                console.log('delete方法调用了');
                return Reflect.deleteProperty(target,prop)
            }
        })
        console.log(proxyUser.name);
        proxyUser.name = '鸣人'  //通过代理对象修改目标对象的属性
        console.log(user);
        proxyUser.gander = '男'  //给目标对象添加属性
        console.log(user);
        delete proxyUser.name
        console.log(user);
        //通过代理对象修改目标对象的属性对象(深度监视)
        proxyUser.wife.name = '雏田' 
        console.log(user);
    </script>
</body>
</html>